package servlet;

import dao.OrderDao;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "OrderListServlet", value = "/OrderListServlet.s")
public class OrderListServlet extends HttpServlet {
    OrderDao dao = new OrderDao();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String orderid = request.getParameter("orderid");
        String receivername = request.getParameter("receivername");

        String status = request.getParameter("status");

        String createtime = request.getParameter("createtime");
        if (createtime!=null){
            final Date date = new Date();
        }

        // 获取当前显示条数
        String pageSize = request.getParameter("pageSize");
        //获取当前页码
        String currentPage = request.getParameter("currentPage");

        //把字符串转为int类型
        int size = Integer.valueOf(pageSize); //size表示每页多条数据
        int page = Integer.valueOf(currentPage);
        //分页查询条件 begin表示从表中第几条数据开始查 size 表示每页多少条数据
        int begin = size * (page - 1);

        //查询总行数total
        long total = dao.queryTotal(receivername,orderid,status,createtime);
        //查询用户数据
         //分页查询
        List<Map<String, Object>> data = dao.queryReceivename(receivername,orderid,status,createtime,begin,size);


        Map<String,Object> result = new HashMap<>();
        result.put("data",data);
        result.put("total",total);
        String json = new Gson().toJson(result);
        response.getWriter().print(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
